<?php

namespace app\api\model;

use think\Model;
use think\model\concern\SoftDelete;

class HandlerModel extends ApiModel
{

    use SoftDelete;


    // 表名
    protected $name = 'handler';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = 'delete_time';

    // 追加属性
    protected $append = [

    ];


    public function getHandler($prams = array())
    {
        $area_name = $prams['area_name'] ?? '';
        //查询所有地区的价格
        $area_price = (new HandlerPrice())->where(['area_name' => $area_name])->column('price', 'handler_id');
        $list = self::where(['status' => 1])
            ->field('id,tag,price,desc,content,level,nums,bondContent')
            ->order('sort desc,id desc')->select();
        foreach ($list as &$value) {
            if (isset($area_price[$value['id']])) {
                $value['price'] = $area_price[$value['id']];
            }
        }
        return $this->api_success('获取成功', $list);

    }

    public function getAdviseInfo($params = array())
    {
        $advise_level = $params['advise_level'] ?? 0;
        //查询财税顾问的等级
        $advise = (new self())->where(['level' => $advise_level])->find();
        $data = [];
        if ($advise) {
            $data['advise_name'] = $advise['tag'] . '-财税顾问';
            $data['advise_content'] = $advise['content'];
            $data['bondContent'] = $advise['bondContent'];
        }

        return $this->api_success('获取成功', $data);
    }


}
